<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * Ajax Update Node Title Action
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 23.04.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/

    /***
    * class ajaxUpdateNode
    ****
    * This class will update the title of the given node
    ****
    * @package ajax
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @since 23.04.2005
    * @copyright essentialmind.com 2005
    ***/
    class ajaxUpdateNode extends ajaxAction{

        public function process(){
            //set variables
            $title  = (string)trim($this->unescape($_REQUEST['value']));
            $id     = (int)$_REQUEST['id'];
			
            //fix inputs
            //$title  = $this->unescape($title);
            $title  = htmlspecialchars($title); 

            //see if the title is accceptable
            if(empty($title)){
                $title = 'n/a';
            }

            //get unwanted symbols out of title
            $title = str_replace("\"","",addslashes($title));

            //see if we can handle the request
            try{
                $this->db->Execute("UPDATE objectmap SET title = '$title' WHERE nodeid = '$id' AND version = 1");
                
                //record action
                $this->log->recordAction("Ajax: Node ($id) title changed to \"".$title."\"");
            }catch(Exception $e){
                
                //record error
                $this->log->recordError("Ajax: Could not set new title for node $id, reason: ".$e->getMessage());
            }
            
			$this->smarty->assign('title',$title);
			$this->smarty->assign('id',$id);
			
			$this->r->html = $this->smarty->preFetch('ajax'.DIRECTORY_SEPARATOR.'nodeupdate.html');
        }
    }
?>